var app = angular.module('searchList', []);
app.controller('listController', function ($scope,$http) {
    getData();
    $scope.addType = "";
    $scope.type = type;
    $scope.key = key;
    $scope.data = [];
    function getData() {
        $http.post("../search/searchList",{
            params: {
                type:type,
                key:key
            }
        }).then(function (result) {
            console.log(result)
            $scope.data = result.data;

        });
    };

    $scope.allData = function(addType) {
        $scope.addType = addType||'';
        getData(addType);
    };

    $scope.toDetail = function(rowId,type) {
        if(type == 'stockrecommend')
            location.href="../stockrecommend/stockrecommenddetail?rowId="+rowId+"&page=search";
        if(type == 'stockpool')
            location.href="../stockpool/stockpooldetail?rowId="+rowId+"&page=search";
        if(type == 'mconference')
            location.href="../morningconference/morningconferencedetail?rowId="+rowId+"&page=search";
        if(type == 'strategymeeting')
            location.href="../schedule/strategy/detail?rowId="+rowId;
        if(type == 'survey')
            location.href="../schedule/survey/detail?rowId="+rowId;
        if(type == 'tel')
            location.href="../schedule/teleconference/detail?rowId="+rowId;
        if(type == 'roadshow')
            location.href="../schedule/roadshow/detail?rowId="+rowId;
        if(type == 'knowledgecenter')
            location.href="../knowledge/detail/"+rowId;

    };
    $scope.getRealPercent = function(val,importPrice){
        console.log(val)
        var realRate = getRealRate(importPrice, val);
        return toDecimal(realRate) + "%";
    }
    function getRealRate(importPrice, realPrice) {
        return (realPrice - importPrice) * 100 / importPrice
    };

    function toDecimal(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return;
        }
        f = Math.round(x * 100) / 100;
        return f;
    };
});

